package nextee.cabletest.controller;

import javafx.collections.ObservableList;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.Node;
import javafx.scene.control.Label;
import javafx.scene.layout.Pane;
import javafx.scene.layout.VBox;
import nextee.cabletest.protocol.ProtocolData;

import java.net.URL;
import java.util.List;
import java.util.ResourceBundle;

/**
 * Created by Administrator on 2015/4/28.
 */
public class RealDataController extends BaseController implements Initializable{
    @FXML
    private VBox ch0;
    @FXML
    private VBox ch1;
    @FXML
    private VBox ch2;
    @FXML
    private VBox ch3;
    @FXML
    private VBox ch4;

    @Override
    public void initialize(URL location, ResourceBundle resources) {

    }

    private void setData(Node pane, int voltage, int current){
        ObservableList<Node> list = ((Pane)pane).getChildren();
        Label a = (Label)list.get(0);
        a.setText(String.valueOf(voltage));
        Label b = (Label)list.get(1);
        b.setText(String.valueOf(current));
    }

    public void setCurrentData(ProtocolData protocolData){
        List<Node> list;
        switch(protocolData.channel){
            case 0:
                list = ch0.getChildren().subList(1, ch0.getChildren().size());
                setData(list.get(protocolData.position), protocolData.voltage, protocolData.current);
                break;
            case 1:
                list = ch1.getChildren().subList(1, ch1.getChildren().size());
                setData(list.get(protocolData.position), protocolData.voltage, protocolData.current);
                break;

            case 2:
                list = ch2.getChildren().subList(1, ch2.getChildren().size());
                setData(list.get(protocolData.position), protocolData.voltage, protocolData.current);
                break;

            case 3:
                list = ch3.getChildren().subList(1, ch3.getChildren().size());
                setData(list.get(protocolData.position), protocolData.voltage, protocolData.current);
                break;
            case 4:
                list = ch4.getChildren().subList(1, ch4.getChildren().size());
                setData(list.get(protocolData.position), protocolData.voltage, protocolData.current);
                break;
        }
        protocolData.debug();

    }
}
